package com.cf.studiomanage.mapper;

import com.cf.studiomanage.entity.ActivityRegistration;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityRegistrationMapper {

    @Insert("INSERT INTO activity_registration(user_id, activity_id, status) VALUES(#{userId}, #{activityId}, 'REGISTERED')")
    int register(ActivityRegistration reg);

    @Update("UPDATE activity_registration SET status = 'LEAVE', reason = #{reason} WHERE user_id = #{userId} AND activity_id = #{activityId}")
    int requestLeave(@Param("userId") Long userId, @Param("activityId") Long activityId, @Param("reason") String reason);

    @Update("UPDATE activity_registration SET signed_in = TRUE WHERE user_id = #{userId} AND activity_id = #{activityId} AND sign_code = #{signCode}")
    int signIn(@Param("userId") Long userId, @Param("activityId") Long activityId, @Param("signCode") String signCode);

    @Select("SELECT * FROM activity_registration WHERE activity_id = #{activityId}")
    List<ActivityRegistration> getRegistrationsByActivity(Long activityId);
}
